<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:pe="http://primefaces.org/ui/extensions"
      >

    <h:outputScript library="javascript" name="media/js/jquery.formatCurrency.js" target="head" />

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form  id="verAto" > 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('config.xhtml')}" value="Configurações" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexEmolumento.xhtml')}" value="Emolumento" update="@form" immediate="true"/> >
                    <p:commandLink  value="Cadastrar Emolumento" update="@form" immediate="true"/>
                </div>
                 <p:messages id="msg"/>
                <p:panel header="Emolumento">                        
                    <fieldset>
                        <legend>Dados do Emolumento</legend>
                        <h:panelGrid  id="panelHeader" columns="2" border="0" styleClass="textAlignRightBold">
                            <h:outputLabel value="Descrição : "/>
                            <p:inputTextarea cols="90"  value="#{managerEmolumento.emolumento.descricao}" size="60"/> 
                            <h:outputLabel value="Data Vigor : "/>
                         <p:row>  
                            <p:calendar value="#{managerEmolumento.emolumento.datVigor}"  mode="popup" showOn="both" pattern="dd/MM/yyyy" />
                            <h:outputText value="Valor do Selo : " style="margin-left: 10px"/>
                            <p:inputText value="#{managerEmolumento.emolumento.valorSelo}" 
                                         onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                             </p:inputText>
                          </p:row>
                            
                        </h:panelGrid>
                    </fieldset>
                    <br/>                    

                    <fieldset>
                        <legend>Itens Emolumento</legend>   
                        <h:panelGrid id="panelSelos" width="950" columns="1" border="0" styleClass="textAlignRightBold" >  
                            <h:panelGrid  columns="2" border="0" styleClass="textAlignRightBold">  
                                <h:outputLabel value="Código Ato:"/>
                                <p:autoComplete id="Ato" panelStyle="width:250px !important;" effect="blind" value="#{managerEmolumento.emolumentoItem.atoItem}" completeMethod="#{managerEmolumento.completeAtoItem}"  
                                                var="p" itemLabel="#{p.codigo} - #{p.descricao}" itemValue="#{p}" converter="atoItemConverter" forceSelection="true" converterMessage="Erro, verifique o Tipo Selo" 
                                                minQueryLength="3" dropdown="true" 
                                                required="true" requiredMessage="O campo 'Ato Tipo' é obrigatório" size="40" scrollHeight="100" > 
                                    <p:ajax event="itemSelect" listener="#{managerEmolumento.handleSelect}"/>  
                                </p:autoComplete>

                            </h:panelGrid>
                            <h:panelGrid  columns="8" border="0" styleClass="textAlignRightBold">  

                                <h:outputLabel value="Cartório:"/>
                                <p:inputText value="#{managerEmolumento.emolumentoItem.cartorio}" size="15" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                                </p:inputText>

                                <h:outputLabel value="Fermojupi:"/>
                                <p:inputText value="#{managerEmolumento.emolumentoItem.fermojupi}" size="15" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                                </p:inputText>

                                <h:outputLabel value="Valor Total:"/>
                                <p:inputText value="#{managerEmolumento.emolumentoItem.valor}" size="15" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                                </p:inputText>


                                <h:outputLabel value="Oab:"/>
                                <p:selectBooleanButton value="#{managerEmolumento.emolumentoItem.oab}" onLabel="Sim" offLabel="Não" />

                                <h:outputLabel id="target" value="Valor Inicial: "/>
                                <p:inputText  value="#{managerEmolumento.emolumentoItem.valInicial}" size="15" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                                </p:inputText>

                                <h:outputLabel value="Valor Final:"/>
                                <p:inputText value="#{managerEmolumento.emolumentoItem.valFinal}" size="15" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" />
                                </p:inputText> 

                            </h:panelGrid> 
                            <br/>
                            <p:row>
                                <center>
                                    <p:commandButton icon="ui-icon-close" value="Limpar" type="reset"  update="@form" immediate="true"/>
                                    <p:commandButton icon="ui-icon-disk" value="Adicionar"  actionListener="#{managerEmolumento.addList()}" process="@this, panelSelos" update="distribuirSelos, panelSelos, msg" />
                                </center>
                                <br/>
                            </p:row>

                            <p:dataTable var="itemsEmol" id="distribuirSelos" 
                                         value="#{managerEmolumento.lstEmolItem}"
                                         rows="20" emptyMessage="Nenhum Emolumento adicionado">  
                                <f:facet name="header">  
                                    Items do Emolumento
                                </f:facet>  
                                <p:column headerText="Ato" style="text-align: center;">  

                                    <table >
                                        <tr >
                                            <td style="width: 40px; background-color: \##{itemsEmol.atoItem.tipoSelo.corSelo.cor};">
                                            </td>
                                            <td>
                                                <h:outputText value="#{itemsEmol.atoItem.codigo}-#{itemsEmol.atoItem.descricao}" />  
                                            </td>

                                        </tr>
                                    </table> 
                                </p:column>
                                <p:column headerText="Cartorio" style="width: 80px" >  
                                    <h:outputText value="#{itemsEmol.cartorio}" style="float: right;" >
                                        <f:convertNumber type="currency" />
                                    </h:outputText>  
                                </p:column>
                                <p:column headerText="Fermojupi"  style="width: 80px">  
                                    <h:outputText value="#{itemsEmol.fermojupi}" style="float: right;">
                                        <f:convertNumber type="currency" />
                                    </h:outputText>  
                                </p:column>
                                <p:column headerText="Valor" style="width: 80px">  
                                    <h:outputText value="#{itemsEmol.valor}" style="float: right;">
                                        <f:convertNumber type="currency" />
                                    </h:outputText>  
                                </p:column>
                                <p:column headerText="Opc" style="width: 43px">  
                                    <p:commandButton  style="width: 20px; height: 20px;" actionListener="#{managerEmolumento.remove(itemsEmol)}"  icon="ui-icon-trash" process="@this" update="@form"/>
                                    <p:commandButton  style="width: 20px; height: 20px;" actionListener="#{managerEmolumento.editar(itemsEmol)}" icon="editar"  process="@this" update="@form"/>
                                </p:column>

                                
                                
                                
                            </p:dataTable>
                        </h:panelGrid>
                    </fieldset>    
                    <br/>
                    <center>
                        <p:commandButton icon="ui-icon-arrowreturnthick-1-w" value="Cancelar" actionListener="#{managerIndex.redirect('indexEmolumento.xhtml')}"   update="@form" immediate="true"/>
                        <p:commandButton icon="ui-icon-disk" value="Salvar"  actionListener="#{managerEmolumento.salvar()}" process="@this, panelHeader" update="panelHeader, msg, @form" />
                    </center>
                </p:panel>
                 

            </h:form>     
        </ui:define>
    </ui:composition>
</html>

